package br.com.amadeus.android.adapters;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import br.com.amadeus.android.activities.home.R;
import br.com.amadeus.android.business.FacadeAmadeusDroid;
import br.com.amadeus.android.entities.Forum;
import br.com.amadeus.android.entities.Resource;

public class LearningResourcesAdapter extends BaseAdapter {
	protected static final String CATEGORIA = "livro";
	private Context context;
	private List<Resource> listResources;
	
	public LearningResourcesAdapter(Context context,
			List<Resource> listResources) {
		super();
		this.context = context;
		this.listResources = listResources;
	}

	public int getCount() {
		return this.listResources.size();
	}

	public Object getItem(int posicao) {
		Resource res = this.listResources.get(posicao);
		return res;
	}

	public long getItemId(int posicao) {
		return posicao;
	}

	public View getView(int posicao, View view, ViewGroup vg) {
		
		LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		View v = inflater.inflate(R.layout.amadeus_resources_detail, null);
		
		Resource resource = this.listResources.get(posicao);
		TextView tv = (TextView) v.findViewById(R.id.tvResourceNameDetail);
				
		ImageView iv = (ImageView) v.findViewById(R.id.ivResourceImgDetail);
		if (resource.getForum().getId() == 0) {
			tv.setText(resource.getName());
			if (resource.getExtension().equalsIgnoreCase("pdf")) {
				iv.setImageResource(R.drawable.apostila);
			}else if (resource.getExtension().equalsIgnoreCase("mp3") || 
					resource.getExtension().equalsIgnoreCase("wav")) {
				iv.setImageResource(R.drawable.som);
				
			}else if (resource.getExtension().equalsIgnoreCase("doc") || 
					resource.getExtension().equalsIgnoreCase("docx")) {
				iv.setImageResource(R.drawable.doc);
			}else if (resource.getExtension().equalsIgnoreCase("ppt") || 
					resource.getExtension().equalsIgnoreCase("pptx") || 
					resource.getExtension().equalsIgnoreCase("pps") || 
					resource.getExtension().equalsIgnoreCase("ppsx")) {
				iv.setImageResource(R.drawable.ppt);
			}else if (resource.getExtension().equalsIgnoreCase("jpg") || 
					resource.getExtension().equalsIgnoreCase("jpeg")) {
				iv.setImageResource(R.drawable.jpg);
			}else if (resource.getExtension().equalsIgnoreCase("png")) {
				iv.setImageResource(R.drawable.png);
			}
		}else{
			Forum forum = FacadeAmadeusDroid.getInstance().getForum(resource.getForum().getId());
			tv.setText(forum.getName());
			iv.setImageResource(R.drawable.forum_small);
		}
		
		
		return v;
	}

}
